package com.testplatfrom.project.controller;


import com.testplatfrom.common.core.domain.R;
import com.testplatfrom.common.log.annotation.Log;
import com.testplatfrom.common.log.enums.BusinessType;
import com.testplatfrom.common.security.annotation.RequiresPermissions;
import com.testplatfrom.project.domain.dto.environment.TestplatfromEnvironmentDetail;
import com.testplatfrom.project.domain.dto.environment.TestplatfromProjectEnvirmentPage;
import com.testplatfrom.project.service.TestplatfromEnvironmentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杨森
 * @since 2023-07-27
 */
@RestController
@RequestMapping("/testplatfromEnvironment")
public class TestplatfromEnvironmentController {

    @Autowired
    private TestplatfromEnvironmentService testplatfromEnvironmentService;

    @ApiOperation(value = "环境管理列表", notes = "环境管理列表")
    @RequiresPermissions("project:environment:list")
    @PostMapping("/list")
    public R environmentList(@RequestBody TestplatfromProjectEnvirmentPage testplatfromProjectEnvirmentPage){
        return R.ok(testplatfromEnvironmentService.listTestplatfromEnvironment(testplatfromProjectEnvirmentPage));
    }

    @ApiOperation(value = "新增环境", notes = "新增环境")
    @RequiresPermissions("project:environment:add")
    @Log(title = "新增环境", businessType = BusinessType.INSERT)
    @PostMapping
    public R addTestplatfromEnvironment(@Valid @RequestBody TestplatfromEnvironmentDetail testplatfromEnvironmentDetail){
        return R.ok(testplatfromEnvironmentService.addTestplatfromEnvironment(testplatfromEnvironmentDetail));
    }


    @ApiOperation(value = "查看详情", notes = "查看详情")
    @RequiresPermissions("project:environment:detail")
    @GetMapping("/detail/{environmentId}")
    public R getTestplatfromEnvironment(@PathVariable("environmentId") String environmentId){
        return R.ok(testplatfromEnvironmentService.getTestplatfromEnvironment(environmentId));
    }


    /**
     * 删除项目管理
     *
     * @return
     */
    @ApiOperation(value = "删除环境", notes = "删除环境")
    @RequiresPermissions("project:environment:remove")
    @Log(title = "删除环境", businessType = BusinessType.DELETE)
    @DeleteMapping("/{environmentId}")
    public R<Boolean> remove(@PathVariable String environmentId) {
        return R.ok(testplatfromEnvironmentService.deleteEnviroment(environmentId));
    }
}

